#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 编译链接外部库 -lpthread

void *start_routine(void *arg)
{
    time_t seconds;
    while (1)
    {
        time(&seconds);
        printf("Current time: %s", ctime(&seconds));
        sleep(2);
    }
}

int main(void)
{

    // 创建一个线程
    pthread_t thread;
    int res = pthread_create(&thread, NULL, start_routine, NULL);
    printf("res = %d\n", res);

    pthread_join(thread, NULL);
}